package software.design.pattern.creative.abstractt.factory;

/**
 * @author soento
 */
public class FarmTest {
    public static void main(String[] args) {
        try {
            Farm f = new SGfarm();
            Animal a = f.newAnimal();
            Plant p = f.newPlant();
            a.show();
            p.show();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        try {
            Farm f = new SRfarm();
            Animal a = f.newAnimal();
            Plant p = f.newPlant();
            a.show();
            p.show();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

/**
 * 抽象产品：动物类
 */
interface Animal {
    void show();
}

/**
 * 具体产品：马类
 */
class Horse implements Animal {

    @Override
    public void show() {
        System.out.println("具体产品：马类");
    }
}

/**
 * 具体产品：牛类
 */
class Cattle implements Animal {

    @Override
    public void show() {
        System.out.println("具体产品：牛类");
    }
}

/**
 * 抽象产品：植物类
 */
interface Plant {
    void show();
}

/**
 * 具体产品：水果类
 */
class Fruitage implements Plant {

    @Override
    public void show() {
        System.out.println("具体产品：水果类");
    }
}

/**
 * 具体产品：蔬菜类
 */
class Vegetables implements Plant {

    @Override
    public void show() {
        System.out.println("具体产品：蔬菜类");
    }
}

/**
 * 抽象工厂：农场类
 */
interface Farm {
    Animal newAnimal();

    Plant newPlant();
}

/**
 * 具体工厂：韶关农场类
 */
class SGfarm implements Farm {
    @Override
    public Animal newAnimal() {
        System.out.println("新牛出生！");
        return new Cattle();
    }

    @Override
    public Plant newPlant() {
        System.out.println("蔬菜长成！");
        return new Vegetables();
    }
}

/**
 * 具体工厂：上饶农场类
 */
class SRfarm implements Farm {
    @Override
    public Animal newAnimal() {
        System.out.println("新马出生！");
        return new Horse();
    }

    @Override
    public Plant newPlant() {
        System.out.println("水果长成！");
        return new Fruitage();
    }
}
